package com.yourenbang.lingyun.transaction.web.controller.manage;

import com.yourenbang.lingyun.constants.enums.pay.PayFromEnum;
import com.yourenbang.lingyun.constants.enums.pay.PayTypeEnum;
import com.yourenbang.lingyun.core.base.controller.BaseController;
import com.yourenbang.lingyun.core.message.Result;
import com.yourenbang.lingyun.core.model.vo.PageVO;
import com.yourenbang.lingyun.domain.PayChannel;
import com.yourenbang.lingyun.transaction.web.domain.dto.pay.*;
import com.yourenbang.lingyun.transaction.web.domain.po.TSPayType;
import com.yourenbang.lingyun.transaction.web.domain.po.TsPayChannel;
import com.yourenbang.lingyun.transaction.web.service.pay.PayTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 支付方式
 */
@Slf4j
@RestController
@RequestMapping("/transaction/manage/paytype")
public class ManagePayTypeController extends BaseController {

    @Autowired
    private PayTypeService payTypeService;

    /**
     * 支付方式-下拉支付方式
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/3046">火眼接口连接</a>
     */
    @RequestMapping(value = "/getPayType", method = RequestMethod.POST)
    public Result<List<Map<String, String>>> getPayType(){
        List<Map<String, String>> list = new ArrayList<>();
        for(PayTypeEnum payType : PayTypeEnum.values()){
            Map<String, String> map = new HashMap<>();
            map.put(payType.getCode(), payType.getName());
            list.add(map);
        }
        return Result.builder().success(list);
    }

    /**
     * 支付方式-下拉支付场景
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/3054">火眼接口连接</a>
     */
    @RequestMapping(value = "/getPayFrom", method = RequestMethod.POST)
    public Result<List<Map<String, String>>> getPayFrom(@RequestBody GetPayFromDTO dto){
        List<Map<String, String>> list = new ArrayList<>();
        for(PayFromEnum payFrom : PayFromEnum.values()){
            if(!dto.getPlatNo().equals(payFrom.getPlatNo())){
                continue;
            }
            Map<String, String> map = new HashMap<>();
            map.put(payFrom.getCode(), payFrom.getName());
            list.add(map);
        }
        return Result.builder().success(list);
    }

    /**
     * 支付方式-列表
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/2958">火眼接口连接</a>
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result<PageVO<TSPayType>> list(@RequestBody PayTypeListDTO dto) {
        return Result.builder().success(payTypeService.list(dto));
    }

    /**
     * 支付方式-保存
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/3062">火眼接口连接</a>
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Result<Void> add(@RequestBody PayTypeAddDTO dto){
        payTypeService.add(dto);
        return Result.builder().success();
    }

    /**
     * 支付方式-修改
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/3094">火眼接口连接</a>
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Result<Void> update(@RequestBody PayTypeAddDTO dto){
        payTypeService.update(dto);
        return Result.builder().success();
    }

    /**
     * 支付方式-删除
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/3102">火眼接口连接</a>
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Result<Void> delete(@RequestBody PayTypeDeleteDTO dto){
        payTypeService.delete(dto);
        return Result.builder().success();
    }

    /**
     * 支付方式-下拉支付通道
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/3110">火眼接口连接</a>
     */
    @RequestMapping(value = "/getChannel", method = RequestMethod.POST)
    public Result<List<PayChannel>> getChannel(@RequestBody GetChannelDTO dto){
        return Result.builder().success(payTypeService.getChannel(dto));
    }

    /**
     * 支付通道-列表
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/3158">火眼接口连接</a>
     */
    @RequestMapping(value = "/channelList", method = RequestMethod.POST)
    public Result<PageVO<TsPayChannel>> channelList(@RequestBody PayChannelListDTO dto) {
        return Result.builder().success(payTypeService.channelList(dto));
    }

    /**
     * 支付通道-保存
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/3166">火眼接口连接</a>
     */
    @RequestMapping(value = "/channelAdd", method = RequestMethod.POST)
    public Result<Void> channelAdd(@RequestBody PayChannelAddDTO dto) {
        payTypeService.channelAdd(dto);
        return Result.builder().success();
    }

    /**
     * 支付通道-修改
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/3174">火眼接口连接</a>
     */
    @RequestMapping(value = "/channelUpdate", method = RequestMethod.POST)
    public Result<Void> channelUpdate(@RequestBody PayChannelAddDTO dto) {
        payTypeService.channelUpdate(dto);
        return Result.builder().success();
    }

    /**
     * 支付通道-删除
     * @see <a href="https://huoyan.kaolakuaishou.cn/project/97/interface/api/3182">火眼接口连接</a>
     */
    @RequestMapping(value = "/channelDelete", method = RequestMethod.POST)
    public Result<Void> channelDelete(@RequestBody PayChannelDeleteDTO dto){
        payTypeService.channelDelete(dto);
        return Result.builder().success();
    }

}
